package com.freewater.parking.adapter;

import com.freewater.parking.application.ParkingAppService;
import com.freewater.parking.domain.common.PlateNumber;
import com.freewater.parking.domain.parking.CalculateFeeCommand;
import com.freewater.parking.domain.parking.CheckInCommand;
import com.freewater.parking.domain.parking.CheckOutCommand;
import com.freewater.parking.domain.parking.NotifyPayCommand;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/parking")
public class ParkingController {

    private ParkingAppService parkingAppService;

    @PostMapping("/checkIn")
    public boolean checkIn(@RequestBody @Validated CheckInRequest checkInRequest) {
        String plateNumber = checkInRequest.getPlateNumber();
        CheckInCommand checkInCommand = new CheckInCommand(new PlateNumber(plateNumber));
        return parkingAppService.checkIn(checkInCommand);
    }

    @PostMapping("/notifyPay")
    public void notifyPay(@RequestBody @Validated NotifyPayRequest notifyPayRequest) {
        String plateNumber = notifyPayRequest.getPlateNumber();
        NotifyPayCommand notifyPayCommand = new NotifyPayCommand(new PlateNumber(plateNumber),
                notifyPayRequest.getPayTime(),
                notifyPayRequest.getAmount());
        parkingAppService.notifyPay(notifyPayCommand);
    }

    @PostMapping("/calculateFee")
    public Integer calculateFee(@RequestBody @Validated CalculateFeeRequest calculateFeeRequest) {
        String plateNumber = calculateFeeRequest.getPlateNumber();
        CalculateFeeCommand calculateFeeCommand = new CalculateFeeCommand(new PlateNumber(plateNumber));
        return parkingAppService.calculateFee(calculateFeeCommand);
    }


    @PostMapping("/checkOut")
    public boolean checkOut(@RequestBody @Validated CheckOutRequest checkOutRequest) {
        String plateNumber = checkOutRequest.getPlateNumber();
        CheckOutCommand checkOutCommand = new CheckOutCommand(new PlateNumber(plateNumber));
        return parkingAppService.checkOut(checkOutCommand);
    }

}
